package com.uu.it.tracker.preferences;

import com.android.tracker.R;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class TwitterSettingsMenu extends Activity { 
    /** Called when the activity is first created. */ 
    
    public String user;
    public String pass;
    
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
        
     // load up the layout 
        setContentView(R.layout.loginpage); 
        
        // get the button resource in the xml file and assign it to a local variable of type Button 
        Button launch = (Button)findViewById(R.id.login_button); 
        
        // this is the action listener 
        launch.setOnClickListener( new OnClickListener() 
        { 

		public void onClick(View viewParam) 
          { 
               // this gets the resources in the xml file and assigns it to a local variable of type EditText 
                EditText usernameEditText = (EditText) findViewById(R.id.txt_username); 
                EditText passwordEditText = (EditText) findViewById(R.id.txt_password); 
          
                
                // this just catches the error if the program cant locate the GUI stuff 
                if(!(usernameEditText == null || passwordEditText == null)){ 
                	 // the getText() gets the current value of the text box 
                    // the toString() converts the value to String data type 
                    // then assigns it to a variable of type String 
                    user = usernameEditText.getText().toString(); 
                    pass = passwordEditText.getText().toString();
                    
                	SharedPreferences preferences2 = getSharedPreferences("login", 0);
            		SharedPreferences.Editor editor2 = preferences2.edit();
                    editor2.putString("user",user);
                    editor2.putString("pass",pass);
                    if(editor2.commit()){
                    	setResult(RESULT_OK);
                    }
                                      
                    
                    Intent intent = new Intent();
	                setResult(RESULT_OK, intent);
	                finish();
                }
          }
        } 
        
        ); // end of launch.setOnclickListener 
                
    } 
}

	
	/*private void loginDetailsMethod() {
		// TODO Auto-generated method stub
        Toast.makeText(this,"logged in",Toast.LENGTH_SHORT).show();
		username = "";
		password = "";
		
		AlertDialog.Builder alert = new AlertDialog.Builder(this);
		alert.setTitle("Login");
		alert.setMessage("username:");

		// You can set an EditText view to get user input besides
		// which button was pressed.
		final EditText user = new EditText(this);
		alert.setView(user);
		
		alert.setMessage("password:");
		
		final EditText pass = new EditText(this);
		alert.setView(pass);

		alert.setPositiveButton("Sign in", new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int whichButton) {
		 // String value = input.getText();
		  // Do something with value!
		  }
		});
		alert.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
			 // String value = input.getText();
			  // Do something with value!
			  }
			});
		

		alert.show();
		
	}
*/

	
/*	private void updateStatusMethod() {
		// TODO Auto-generated method stub
		 Toast.makeText(this,"status",Toast.LENGTH_SHORT).show();
	        try{
				TwitterFactory tf = new TwitterFactory();
				Twitter twitter = tf.getInstance("datacom3project", "datacom3");
				twitter.updateStatus("my test10");
			}catch(TwitterException  ex){
				System.out.println("error");	
		        Toast.makeText(this,"exception",Toast.LENGTH_SHORT).show();
			}
		
	}		*/
	

